package com.jdbctemplate.dao;
import com.jdbctemplate.domain.Account;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.List;
public class AccountDaoImple extends  jdbcDaoSuper implements IAccoutDao{
    /*private JdbcTemplate jdbcTemplate;

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
*/
    public Account findbyid(Integer id) {
        List<Account> account=getJdbcTemplate().query("select * from account where id=?",new BeanPropertyRowMapper<Account>(Account.class),id);
        return account.isEmpty()?null:account.get(0);
    }

    public Account findbyname(String name) {
        List<Account> account=getJdbcTemplate().query("select * from account where name=?",new BeanPropertyRowMapper<Account>(Account.class),name);
        if(account.size()>1){
            System.out.println("结果集不唯一");
        }
        if(account.isEmpty()){
            System.out.println("结果集为空");
        }
        return account.get(0);

    }
    public void update(Account account) {
        //update的顺序必须对应
        getJdbcTemplate().update("update account set name=?,money=? where id=?",account.getName(),account.getMoney(),account.getId());
    }
}
